/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.worldscale.javase.wslib.urm;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import net.worldscale.xp.wslib.urm.io.IConnection;
import net.worldscale.xp.wslib.urm.io.IConnectionFactory;
import net.worldscale.xp.wslib.urm.io.IHttpConnection;

/**
 *
 * @author Kun
 */
final class ImplHttpConnection implements IHttpConnection {

    private static class MyFactory implements IConnectionFactory {

        public String getScheme() {
            return "http";
        }

        public IConnection open(String uri) throws IOException {
            return new ImplHttpConnection(uri);
        }
    }

    public static IConnectionFactory getFactory() {
        return new MyFactory();
    }
    private final HttpURLConnection conn;

    private ImplHttpConnection(String uri) throws IOException {
        final URL url = new URL(uri);
        final HttpURLConnection htcon = (HttpURLConnection) url.openConnection();
        this.conn = htcon;
    }

    public long getDate() throws IOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public long getExpiration() throws IOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public String getFile() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public String getHeaderField(int n) throws IOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public String getHeaderField(String name) throws IOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public long getHeaderFieldDate(String name, long def) throws IOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public int getHeaderFieldInt(String name, int def) throws IOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public String getHeaderFieldKey(int n) throws IOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public String getHost() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public long getLastModified() throws IOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public int getPort() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public String getProtocol() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public String getQuery() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public String getRef() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public String getRequestMethod() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public String getRequestProperty(String key) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public int getResponseCode() throws IOException {
        return conn.getResponseCode();
    }

    public String getResponseMessage() throws IOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public String getURL() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void setRequestMethod(String method) throws IOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void setRequestProperty(String key, String value) throws IOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public String getEncoding() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public long getLength() {
        return conn.getContentLength();
    }

    public String getType() {
        return conn.getContentType();
    }

    public DataOutputStream openDataOutputStream() throws IOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public OutputStream openOutputStream() throws IOException {
        return conn.getOutputStream();
    }

    public void close() throws IOException {
        conn.disconnect();
    }

    public DataInputStream openDataInputStream() throws IOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public InputStream openInputStream() throws IOException {
        return conn.getInputStream();
    }
}
